<template>
    <router-view></router-view>
</template>

<script lang="ts">
import { onMounted } from '@vue/runtime-core';
import UserStore from "./store/userstore";
import { useRouter } from 'vue-router'
import { ElMessage } from 'element-plus'

export default {
    name: "App",
    setup(){
      const router = useRouter()
      const store = UserStore();
        window.addEventListener("beforeunload", () => {
            sessionStorage.setItem("store",store.username);
        })
        onMounted(() => {
          if (sessionStorage.getItem("store")) {
              store.username = sessionStorage.getItem("store") || ''
              
          }
          if(store.username === ''){
              router.replace({name:'login'})
              ElMessage.warning('请登录')
          }
        })
    }  
}
</script>

<style>
</style>